package com.zl.config;

import org.springframework.web.servlet.LocaleResolver;
import sun.util.resources.cldr.ru.LocaleNames_ru_UA;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;

/**
 * @author zhanglei2
 * @since 2019/12/12 10:10
 */
public class MyLocaleResolver implements LocaleResolver {
    @Override
    public Locale resolveLocale(HttpServletRequest request) {
        //获取默认的国际化参数
        Locale defaultLocale = Locale.getDefault();
        //获取请求的国际化参数
        String language = request.getParameter("l");
        if(language!=null) {
        //   获取语言参数
            String[] languages = language.split("_");
            defaultLocale = new Locale(languages[0],languages[1]);
        }
        return defaultLocale;
    }

    @Override
    public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) {

    }
}
